home *** CD-ROM | disk | FTP | other *** search
/ Apple WWDC 1996 / WWDC96_1996 (CD).toast / Technology Materials / MacApp Release 10 / MacApp Release 10 - HD Ready / Libraries / Docs / Sources / UEditionDocument.cp < prev    next >
Encoding:
Text File  |  1996-04-03  |  68.3 KB  |  2,090 lines  |  [TEXT/MPS ]

  1. //----------------------------------------------------------------------------------------
  2. // UEditionDocument.cp 
  3. // Copyright © 1984-96 by Apple Computer, Inc. All rights reserved.
  4. //----------------------------------------------------------------------------------------
  5.  
  6. #ifndef __UEDITIONDOCUMENT__
  7. #include "UEditionDocument.h"
  8. #endif
  9.  
  10. // MacApp
  11.  
  12. #ifndef __UAPPLEEVENTS__
  13. #include "UAppleEvents.h"
  14. #endif
  15.  
  16. //    #ifndef __UAPPLICATION__
  17. //    #include "UApplication.h"
  18. //    #endif
  19.  
  20. #ifndef __UCLIPBOARDMGR__
  21. #include "UClipboardMgr.h"
  22. #endif
  23.  
  24. #ifndef __UDEPENDENCIES__
  25. #include "UDependencies.h"
  26. #endif
  27.  
  28. #ifndef __UDESIGNATOR__
  29. #include "UDesignator.h"
  30. #endif
  31.  
  32. #ifndef __UDISPATCHER__
  33. #include "UDispatcher.h"
  34. #endif
  35.  
  36. #ifndef __UERRORMGR__
  37. #include "UErrorMgr.h"
  38. #endif
  39.  
  40. #ifndef __UFILE__
  41. #include "UFile.h"
  42. #endif
  43.  
  44. #ifndef __UGEOMETRY__
  45. #include "UGeometry.h"
  46. #endif
  47.  
  48. #ifndef __UMACAPPGLOBALS__
  49. #include "UMacAppGlobals.h"
  50. #endif
  51.  
  52. #ifndef __UMACAPPUTILITIES__
  53. #include "UMacAppUtilities.h"
  54. #endif
  55.  
  56. #ifndef __UMEMORY__
  57. #include "UMemory.h"
  58. #endif
  59.  
  60. #ifndef __UMENUMGR__
  61. #include "UMenuMgr.h"
  62. #endif
  63.  
  64. #ifndef __USCRIPTING__
  65. #include "UScripting.h"
  66. #endif
  67.  
  68. #ifndef __USECTION__
  69. #include "USection.h"
  70. #endif
  71.  
  72. #ifndef __USECTIONMGR__
  73. #include "USectionMgr.h"
  74. #endif
  75.  
  76. #ifndef __UWINDOW__
  77. #include "UWindow.h"
  78. #endif
  79.  
  80. // Toolbox
  81.  
  82. #ifndef __ERRORS__
  83. #include <Errors.h>
  84. #endif
  85.  
  86. #ifndef __PACKAGES__
  87. #include <Packages.h>
  88. #endif
  89.  
  90. #ifndef __RESOURCES__
  91. #include <Resources.h>
  92. #endif
  93.  
  94. #ifndef __TOOLUTILS__
  95. #include <ToolUtils.h>
  96. #endif
  97.  
  98. // ANSI
  99.  
  100. #ifndef __STDIO__
  101. #include <stdio.h>
  102. #endif
  103.  
  104.  
  105. //----------------------------------------------------------------------------------------
  106. const unsigned long kEditionDocRsrcType = 'EdSt';// rsrc type for Edition Doc private rsrc 
  107. const short kEditionDocRsrcID = 301;             // rsrc id for Edition Doc private rsrc 
  108. extern const char *kEditionDocRsrcName = "Edition Doc Settings";
  109.  
  110. #if PRAGMA_ALIGN_SUPPORTED
  111. #pragma options align=mac68k
  112. #endif
  113. typedef struct EditionDocSettings
  114. {                                                 // used for saving settings in a resource 
  115.     Boolean showSectionBorders;
  116.     Boolean stopAllEditions;
  117. }    *EditionDocSettingsPtr, ** EditionDocSettingsHandle;
  118. #if PRAGMA_ALIGN_SUPPORTED
  119. #pragma options align=reset
  120. #endif
  121.  
  122. //========================================================================================
  123. // CLASS CSectionIterator
  124. //========================================================================================
  125. #undef Inherited
  126. #define Inherited CObjectIterator
  127.  
  128. //----------------------------------------------------------------------------------------
  129. // CSectionIterator::CSectionIterator: 
  130. //----------------------------------------------------------------------------------------
  131. #pragma segment MADocumentRes
  132.  
  133. CSectionIterator::CSectionIterator(TEditionDocument* itsDocument,
  134.                                    ArrayIndex itsLowBound,
  135.                                    ArrayIndex itsHighBound,
  136.                                    Boolean itsForward) :
  137.     CObjectIterator(itsDocument ? itsDocument->fSectionList : NULL, itsLowBound, itsHighBound, itsForward)
  138.  
  139. {
  140. } // CSectionIterator::CSectionIterator 
  141.  
  142. //----------------------------------------------------------------------------------------
  143. // CSectionIterator::CSectionIterator: 
  144. //----------------------------------------------------------------------------------------
  145. #pragma segment MADocumentRes
  146.  
  147. CSectionIterator::CSectionIterator(TEditionDocument* itsDocument,
  148.                                    Boolean itsForward) :
  149.     CObjectIterator(itsDocument ? itsDocument->fSectionList : NULL, itsForward)
  150. {
  151. } // CSectionIterator::CSectionIterator 
  152.  
  153. //----------------------------------------------------------------------------------------
  154. // CSectionIterator::CSectionIterator: 
  155. //----------------------------------------------------------------------------------------
  156. #pragma segment MADocumentRes
  157.  
  158. CSectionIterator::CSectionIterator(TEditionDocument* itsDocument) :
  159.     CObjectIterator(itsDocument ? itsDocument->fSectionList : NULL, kIterateForward)
  160. {
  161. } // CSectionIterator::CSectionIterator 
  162.  
  163. //----------------------------------------------------------------------------------------
  164. // CSectionIterator::CSectionIterator: 
  165. //----------------------------------------------------------------------------------------
  166. #pragma segment MADocumentRes
  167.  
  168. CSectionIterator::CSectionIterator(TSectionList* itsSectionList) :
  169.     CObjectIterator(itsSectionList, kIterateForward)
  170. {
  171. } // CSectionIterator::CSectionIterator 
  172.  
  173. //----------------------------------------------------------------------------------------
  174. // CSectionIterator::~CSectionIterator: 
  175. //----------------------------------------------------------------------------------------
  176. #pragma segment MADocumentRes
  177.  
  178. CSectionIterator::~CSectionIterator()
  179. {
  180. } // CSectionIterator::~CSectionIterator 
  181.  
  182. //----------------------------------------------------------------------------------------
  183. // CSectionIterator::CurrentSection: 
  184. //----------------------------------------------------------------------------------------
  185. #pragma segment MADocumentRes
  186.  
  187. TSection* CSectionIterator::CurrentSection()
  188. {
  189.     return (TSection*)this->CurrentObject();
  190. } // CSectionIterator::CurrentSection 
  191.  
  192. //----------------------------------------------------------------------------------------
  193. // CSectionIterator::FirstSection: 
  194. //----------------------------------------------------------------------------------------
  195. #pragma segment MADocumentRes
  196.  
  197. TSection* CSectionIterator::FirstSection()
  198. {
  199.     return (TSection*)this->FirstObject();
  200. } // CSectionIterator::FirstSection 
  201.  
  202. //----------------------------------------------------------------------------------------
  203. // CSectionIterator::NextSection: 
  204. //----------------------------------------------------------------------------------------
  205. #pragma segment MADocumentRes
  206.  
  207. TSection* CSectionIterator::NextSection()
  208. {
  209.     return (TSection*)this->NextObject();
  210. } // CSectionIterator::NextSection 
  211.  
  212.  
  213. //========================================================================================
  214. // GLOBAL Procedures
  215. //========================================================================================
  216. #undef Inherited
  217.  
  218. //----------------------------------------------------------------------------------------
  219. // InitUEditionDocument: 
  220. //----------------------------------------------------------------------------------------
  221. #pragma segment MAInit
  222.  
  223. void InitUEditionDocument()
  224. {
  225.     FailOSErr(InitEditionPack());
  226.     
  227.     MA_REGISTER_SIGNATURE(TSectionBehavior, kSectionBehavior);
  228.  
  229.     // debug check to ensure that the user has included Editions.r in their <program>.r file
  230. #if qDebugMsg
  231. const short kAEEditionsDispatchTable = 401;        // ID of our 'aedt' resource
  232.     Handle aedtResource = GetResource('aedt', kAEEditionsDispatchTable);
  233.     if (!aedtResource)
  234.     {
  235.         fprintf(stderr, "###Missing 'aedt' resource id=%d!\n", kAEEditionsDispatchTable);
  236.         ProgramBreak("Did you forget to include Editions.rsrc in your .r file?\n");
  237.     }
  238. #endif
  239. } // InitUEditionDocument 
  240.  
  241.  
  242. //========================================================================================
  243. // CLASS TEditionDocument
  244. //========================================================================================
  245. #undef Inherited
  246. #define Inherited TFileBasedDocument
  247.  
  248. #pragma segment MAOpen
  249. MA_DEFINE_CLASS_M1(TEditionDocument, Inherited);
  250.  
  251. //----------------------------------------------------------------------------------------
  252. // TEditionDocument constructor
  253. //----------------------------------------------------------------------------------------
  254. #pragma segment MAOpen
  255.  
  256. TEditionDocument::TEditionDocument()
  257. {
  258.     fSectionList = NULL;
  259.     fStopAllEditions = FALSE;
  260.     fShowSectionBorders = TRUE;
  261.     fNextEditionNumber = 1;
  262.     fNewPublishers = FALSE;
  263.     fEditionCreator = '\?\?\?\?';
  264. } // TEditionDocument::TEditionDocument
  265.  
  266. //----------------------------------------------------------------------------------------
  267. // TEditionDocument::IEditionDocument: 
  268. //----------------------------------------------------------------------------------------
  269. #pragma segment MAOpen
  270.  
  271. void TEditionDocument::IEditionDocument(TFile* itsFile,
  272.                                         const OSType itsScrapType,
  273.                                         const OSType editionCreator)
  274. {
  275.     this->IFileBasedDocument(itsFile, itsScrapType);
  276.  
  277.     fEditionCreator = editionCreator;
  278.     
  279.     FailInfo fi;
  280.     Try(fi)
  281.     {
  282.         TSectionList* aSectionList = new TSectionList;
  283.         aSectionList->ISectionList();
  284.         fSectionList = aSectionList;
  285.         fi.Success();
  286.     }
  287.     else
  288.     {
  289.         this->Free();
  290.         fi.ReSignal();
  291.     }
  292.  
  293. #if qDebug
  294.         fSectionList->SetEltType("TSection");    // takes MAName
  295. #endif
  296.  
  297.     InitUSectionMgr();                            // ensure it's init'd
  298. } // TEditionDocument::IEditionDocument 
  299.  
  300. //----------------------------------------------------------------------------------------
  301. // TEditionDocument::Free: 
  302. //----------------------------------------------------------------------------------------
  303. #pragma segment MAClose
  304.  
  305. TEditionDocument::~TEditionDocument()
  306. {
  307.     fSectionList = (TSectionList *)FreeListIfObject(fSectionList);
  308. } // TEditionDocument::Free 
  309.  
  310. //----------------------------------------------------------------------------------------
  311. // TEditionDocument::FreeData: 
  312. //----------------------------------------------------------------------------------------
  313. #pragma segment MAClose
  314.  
  315. void TEditionDocument::FreeData()    // override 
  316. {
  317.     fSectionList->FreeAll();
  318.  
  319.     Inherited::FreeData();
  320. } // TEditionDocument::FreeData 
  321.  
  322. //----------------------------------------------------------------------------------------
  323. // TEditionDocument::CanPublishSelection: 
  324. //----------------------------------------------------------------------------------------
  325. #pragma segment MADocumentRes
  326.  
  327. Boolean TEditionDocument::CanPublishSelection()
  328. {
  329.     // we can publish if:
  330.     // 1. there is a user selection, and
  331.     // 2. the user selection contains something, and
  332.     // 3. there isn't already a non-canceled publisher EXACTLY contained in the current selection.
  333.  
  334.     TDesignator * userSelection;
  335.     if ((userSelection = this->GetUserSelection()) != NULL)
  336.     {
  337.         if (!userSelection->IsEmpty())
  338.         {
  339.             CSectionIterator iter(this);
  340.             
  341.             for (TSection* aSection = iter.FirstSection(); iter.More(); aSection = iter.NextSection())
  342.                 if (!aSection->IsCanceled() && (aSection->GetSectionType() == stPublisher) && userSelection->IsContained(aSection->fDesignator) == kExactlyContained)
  343.                     return FALSE;
  344.         }
  345.         else
  346.             return FALSE;
  347.     }
  348.     else
  349.         return FALSE;                // if there is no selection, then can't publish the selection
  350.  
  351.     return TRUE;
  352. } // TEditionDocument::CanPublishSelection 
  353.  
  354. //----------------------------------------------------------------------------------------
  355. // TEditionDocument::CanSubscribe: 
  356. //----------------------------------------------------------------------------------------
  357. #pragma segment MADocumentRes
  358.  
  359. Boolean TEditionDocument::CanSubscribe()
  360. {
  361.     // we can subscribe if:
  362.     // 1. there is a user selection, and
  363.     // 2. the user selection contains something, and
  364.     // 3. there isn't a non-canceled subscriber currently selected (i.e. don't subscribe OVER a subscriber).
  365.  
  366.     TDesignator * userSelection;
  367.     if ((userSelection = this->GetUserSelection()) != NULL)
  368.     {
  369.         if (!userSelection->IsEmpty())
  370.         {
  371.             CSectionIterator iter(this);
  372.             
  373.             for (TSection* aSection = iter.FirstSection(); iter.More(); aSection = iter.NextSection())
  374.                 if (!aSection->IsCanceled() && (aSection->GetSectionType() == stSubscriber) && userSelection->IsContained(aSection->fDesignator) != kNotContained)
  375.                         return FALSE;
  376.         }
  377.         else
  378.             return FALSE;
  379.     }
  380.     else
  381.         return FALSE;
  382.  
  383.     return TRUE;
  384. } // TEditionDocument::CanSubscribe 
  385.  
  386. //----------------------------------------------------------------------------------------
  387. // TEditionDocument::DoWrite: 
  388. //----------------------------------------------------------------------------------------
  389. #pragma segment MAWriteFile
  390.  
  391. void TEditionDocument::DoWrite(TFile* aFile, Boolean makingCopy)    // override 
  392. {
  393.     Inherited::DoWrite(aFile, makingCopy);
  394.  
  395.     // 0. warn user if doc has multiple publishers to same edition
  396.     {
  397.         CSectionIterator iter(this);
  398.         TSection* aSection;
  399.         TSection* prevPublisher = NULL;
  400.         for (aSection = iter.FirstSection(); iter.More(); aSection = iter.NextSection())
  401.             if (aSection->GetSectionType() == stPublisher)
  402.             {
  403.                 if (prevPublisher)
  404.                 {
  405.                     if ((*(prevPublisher->fSectionHandle))->controlBlock ==
  406.                         (*(aSection->fSectionHandle))->controlBlock)
  407.                     {
  408.                         this->PoseSavingMultPublishersAlert(prevPublisher);
  409.                         break;
  410.                     }
  411.                 }
  412.                 prevPublisher = aSection;
  413.             }
  414.     }
  415.  
  416.     // 1. write out (as a resource) fStopAllEditions and fShowSectionBorders 
  417.     this->DoWriteSettings(aFile);
  418.  
  419.     // 2. clear the new publishers flag 
  420.     fNewPublishers = FALSE;
  421.  
  422.     // 3. tell each section to write itself out 
  423.     {
  424.         CSectionIterator iter(this);
  425.         TSection* aSection;
  426.         for (aSection = iter.FirstSection(); iter.More(); aSection = iter.NextSection())
  427.             aSection->DoWrite(aFile, FALSE);
  428.     }
  429. } // TEditionDocument::DoWrite 
  430.  
  431. //----------------------------------------------------------------------------------------
  432. // TEditionDocument::DoWriteSettings: 
  433. //----------------------------------------------------------------------------------------
  434. #pragma segment MAWriteFile
  435.  
  436. void TEditionDocument::DoWriteSettings(TFile*)
  437. {
  438.     EditionDocSettingsHandle h = (EditionDocSettingsHandle)NewPermHandle(sizeof(EditionDocSettings));
  439.  
  440.     (*h)->showSectionBorders = fShowSectionBorders;
  441.     (*h)->stopAllEditions = fStopAllEditions;
  442.     
  443.     MAAddResource((Handle)h, kEditionDocRsrcType, kEditionDocRsrcID, CStr255(kEditionDocRsrcName));
  444.     FailResError();
  445. } // TEditionDocument::DoWriteSettings 
  446.  
  447. //----------------------------------------------------------------------------------------
  448. // TEditionDocument::DoRead: 
  449. //----------------------------------------------------------------------------------------
  450. #pragma segment MAReadFile
  451.  
  452. void TEditionDocument::DoRead(TFile* aFile, Boolean forPrinting)    // override 
  453. {
  454.     Inherited::DoRead(aFile, forPrinting);
  455.  
  456.     // 1. read in (from a resource) fStopAllEditions and fShowSectionBorders 
  457.     this->DoReadSettings(aFile);
  458.  
  459.     // 2. create the section objects and tell each section to read itself in 
  460.     for (short i = 1; i <= Count1Resources(rSectionType); ++i)
  461.     {
  462.         short theID;
  463.         Handle h;
  464.  
  465.         h = Get1IndResource(rSectionType, i);    // get the resource handle 
  466.         FailNILResource((Handle)h);
  467.         theID = (short)(*((SectionHandle)h))->sectionID;
  468.         switch ((*((SectionHandle)h))->kind)
  469.         {
  470.             case stPublisher:
  471.                 this->DoReadPublisher(aFile, theID);
  472.                 break;
  473.             case stSubscriber:
  474.                 this->DoReadSubscriber(aFile, theID);
  475.                 break;
  476.             default:
  477. #if qDebug
  478.                 ProgramBreak("SectionHandle appears to be corrupt");
  479. #endif
  480.                 break;
  481.         }
  482.     }
  483. } // TEditionDocument::DoRead 
  484.  
  485. //----------------------------------------------------------------------------------------
  486. // TEditionDocument::DoReadSettings: 
  487. //----------------------------------------------------------------------------------------
  488. #pragma segment MAReadFile
  489.  
  490. void TEditionDocument::DoReadSettings(TFile*)
  491. {
  492.     EditionDocSettingsHandle h = (EditionDocSettingsHandle) Get1Resource(kEditionDocRsrcType, kEditionDocRsrcID);
  493.     FailNILResource((Handle)h);
  494.     fShowSectionBorders = (*h)->showSectionBorders;
  495.     fStopAllEditions = (*h)->stopAllEditions;
  496.     ReleaseResource((Handle)h);
  497. } // TEditionDocument::DoReadSettings 
  498.  
  499. //----------------------------------------------------------------------------------------
  500. // TEditionDocument::DoReadPublisher: 
  501. //----------------------------------------------------------------------------------------
  502. #pragma segment MAReadFile
  503.  
  504. void TEditionDocument::DoReadPublisher(TFile* aFile, short theID)
  505. {
  506.     TPublisher * aPublisher = this->DoMakePublisher(NULL, NULL, theID);
  507.     FailInfo fi;
  508.     Try(fi)
  509.     {
  510.         aPublisher->DoRead(aFile);
  511.         fi.Success();
  512.     }
  513.     else
  514.     {
  515.         aPublisher = (TPublisher *)(FreeIfObject(aPublisher));
  516.         fi.ReSignal();
  517.     }
  518.     this->AddSection(aPublisher);
  519. } // TEditionDocument::DoReadPublisher 
  520.  
  521. //----------------------------------------------------------------------------------------
  522. // TEditionDocument::DoReadSubscriber: 
  523. //----------------------------------------------------------------------------------------
  524. #pragma segment MAReadFile
  525.  
  526. void TEditionDocument::DoReadSubscriber(TFile* aFile, short theID)
  527. {
  528.     TSubscriber * aSubscriber = this->DoMakeSubscriber(NULL, NULL, theID);
  529.     FailInfo fi;
  530.     Try(fi)
  531.     {
  532.         aSubscriber->DoRead(aFile);
  533.         fi.Success();
  534.     }
  535.     else
  536.     {
  537.         aSubscriber = (TSubscriber *)(FreeIfObject(aSubscriber));
  538.         fi.ReSignal();
  539.     }
  540.     this->AddSection(aSubscriber);
  541. } // TEditionDocument::DoReadSubscriber 
  542.  
  543. //----------------------------------------------------------------------------------------
  544. // TEditionDocument::RevertDocument: 
  545. //----------------------------------------------------------------------------------------
  546. #pragma segment MAReadFile
  547.  
  548. void TEditionDocument::RevertDocument()
  549. {
  550.     this->Abandon();
  551.     Inherited::RevertDocument();
  552. } // TEditionDocument::RevertDocument 
  553.  
  554. //----------------------------------------------------------------------------------------
  555. // TEditionDocument::DoMenuCommand: 
  556. //----------------------------------------------------------------------------------------
  557. #pragma segment MASelCommand
  558.  
  559. void TEditionDocument::DoMenuCommand(CommandNumber aCommandNumber)// override 
  560.  
  561. {
  562.     switch (aCommandNumber)
  563.     {
  564.         case cCreatePublisher:
  565.             this->DoNewPublisher();
  566.             break;
  567.         case cSubscribeTo:
  568.             {
  569.                 TNewSubscriberCommand* aNewSubscriberCommand = new TNewSubscriberCommand;
  570.                 aNewSubscriberCommand->INewSubscriberCommand(cSubscribeTo, this);
  571.                 this->PostCommand(aNewSubscriberCommand);
  572.                 break;
  573.             }
  574.         case cOptions:
  575.             this->DoSectionOptions();
  576.             break;
  577.         case cBorders:
  578.             {
  579.                 TSectionBorderCommand * aSectionBorderCmd = new TSectionBorderCommand;
  580.                 aSectionBorderCmd->ISectionBorderCommand(cBorders, this);
  581.                 this->PostCommand(aSectionBorderCmd);
  582.                 break;
  583.             }
  584.         case cStopAllEditions:
  585.             {
  586.                 TStopAllEditionsCommand * aStopAllEditionsCmd = new TStopAllEditionsCommand;
  587.                 aStopAllEditionsCmd->IStopAllEditionsCommand(cStopAllEditions, this);
  588.                 this->PostCommand(aStopAllEditionsCmd);
  589.                 break;
  590.             }
  591.         default:
  592.             Inherited::DoMenuCommand(aCommandNumber);
  593.             break;
  594.     }
  595. } // TEditionDocument::DoMenuCommand 
  596.  
  597. //----------------------------------------------------------------------------------------
  598. // TEditionDocument::DoSectionOptions: 
  599. //----------------------------------------------------------------------------------------
  600. #pragma segment MADocumentNonRes
  601.  
  602. void TEditionDocument::DoSectionOptions()
  603.  
  604. {
  605.     TSection * aSection = this->GetSelectedSection();
  606.     if (aSection)
  607.     {
  608.         if (aSection->GetSectionType() == stPublisher)
  609.             this->DoPublisherOptions((TPublisher *)aSection);
  610.         else if (aSection->GetSectionType() == stSubscriber)
  611.             this->DoSubscriberOptions((TSubscriber *)aSection);
  612. #if qDebug
  613.         else
  614.             ProgramBreak("what kind of section is it anyway?");
  615. #endif
  616.     }
  617. } // TEditionDocument::DoSectionOptions 
  618.  
  619. //----------------------------------------------------------------------------------------
  620. // TEditionDocument::Close: 
  621. //----------------------------------------------------------------------------------------
  622. #pragma segment MAClose
  623.  
  624. void TEditionDocument::Close()        // override 
  625. {
  626.     short poseResult = cancel;
  627.     long changeCount;
  628.  
  629.     changeCount = this->GetChangeCount();
  630.     
  631.     // preflight the Close for the case in which the document's DATA is unchanged (the change
  632.     // count is 0) but there are new publishers in the document
  633.     if ((changeCount == 0) && fNewPublishers)
  634.     {
  635.         poseResult = this->PoseNewPublishersAlert();
  636.         if (poseResult == cancel)
  637.             Failure(noErr, messageCancelled);
  638.     }
  639.     else if (changeCount && fAskOnClose)
  640.     {
  641.         poseResult = this->PoseSaveDialog();
  642.         if (poseResult == cancel)
  643.             Failure(noErr, messageCancelled);
  644.     }
  645.  
  646.     this->Changed(mClosed,this);
  647.  
  648.     if (poseResult == kYesButton)
  649.         this->SaveDocument(cClose);                // Will fail if unable to save 
  650.     else if (poseResult == kNoButton)
  651.         this->Abandon();
  652.  
  653.     // Must never be called for a document related to a view in the Clipboard.
  654.     // Why is this???
  655.     CWindowIterator iter(this);
  656.  
  657.     for (TWindow* aWindow = iter.FirstWindow(); iter.More(); aWindow = iter.NextWindow())
  658.         aWindow->CloseAndFree();
  659.  
  660. } // TEditionDocument::Close 
  661.  
  662. //----------------------------------------------------------------------------------------
  663. // TEditionDocument::PoseNewPublishersAlert: 
  664. //----------------------------------------------------------------------------------------
  665. #pragma segment MAClose
  666. short TEditionDocument::PoseNewPublishersAlert()
  667.  
  668. {
  669.     short returnVal = kNoButton;
  670.  
  671.     FailOSErr(MAInteractWithUser());
  672.     
  673.     CStr255 reason;
  674.     GetIndString(reason, kIDBuzzString, gDispatcher->fDone ? bzQuitting : bzClosing);
  675.     ParamText(fTitle, reason, gEmptyString, gEmptyString);
  676.     
  677.     short oldResFile = MACurResFile();
  678.     
  679.     FailInfo fi;
  680.     Try(fi)
  681.     {
  682.         MAUseResFile(gApplicationRefNum);
  683.         returnVal = MacAppAlert(phNewPublisherAlert, NULL);
  684.         fi.Success();
  685.     }
  686.     else
  687.     {
  688.         MAUseResFile(oldResFile);
  689.         fi.ReSignal();
  690.     }
  691.     MAUseResFile(oldResFile);
  692.     
  693.     return returnVal;
  694. } // TEditionDocument::PoseNewPublishersAlert 
  695.  
  696. //----------------------------------------------------------------------------------------
  697. // TEditionDocument::PoseMultPublishersAlert: 
  698. //----------------------------------------------------------------------------------------
  699. #pragma segment MAClose
  700.  
  701. short TEditionDocument::PoseMultPublishersAlert(TSection* aSection)
  702.  
  703. {
  704.     short returnVal = kNoButton;
  705.  
  706.     FailOSErr(MAInteractWithUser());
  707.  
  708.     CStr255 name;
  709.     aSection->GetEditionName(name);
  710.  
  711.     ParamText(name, gEmptyString, gEmptyString, gEmptyString);
  712.     short oldResFile = MACurResFile();
  713.     
  714.     FailInfo fi;
  715.     Try(fi)
  716.     {
  717.         MAUseResFile(gApplicationRefNum);
  718.         returnVal = MacAppAlert(phMultPublisherWrn, NULL);
  719.         fi.Success();
  720.     }
  721.     else
  722.     {
  723.         MAUseResFile(oldResFile);
  724.         fi.ReSignal();
  725.     }
  726.     MAUseResFile(oldResFile);
  727.     
  728.     return returnVal;
  729. } // TEditionDocument::PoseMultPublishersAlert 
  730.  
  731. //----------------------------------------------------------------------------------------
  732. // TEditionDocument::PoseSavingMultPublishersAlert: 
  733. //----------------------------------------------------------------------------------------
  734. #pragma segment MAClose
  735.  
  736. short TEditionDocument::PoseSavingMultPublishersAlert(TSection* aSection)
  737.  
  738. {
  739.     short returnVal = kNoButton;
  740.  
  741.     FailOSErr(MAInteractWithUser());
  742.  
  743.     CStr255 name;
  744.     aSection->GetEditionName(name);
  745.     ParamText(name, fTitle, gEmptyString, gEmptyString);
  746.     short oldResFile = MACurResFile();
  747.     
  748.     FailInfo fi;
  749.     Try(fi)
  750.     {
  751.         MAUseResFile(gApplicationRefNum);
  752.         returnVal = MacAppAlert(phSavingMultPublisherWrn, NULL);
  753.         fi.Success();
  754.     }
  755.     else
  756.     {
  757.         MAUseResFile(oldResFile);
  758.         fi.ReSignal();
  759.     }
  760.     MAUseResFile(oldResFile);
  761.     
  762.     return returnVal;
  763. } // TEditionDocument::PoseSavingMultPublishersAlert 
  764.  
  765. //----------------------------------------------------------------------------------------
  766. // TEditionDocument::Abandon: 
  767. //----------------------------------------------------------------------------------------
  768. #pragma segment MAClose
  769.  
  770. void TEditionDocument::Abandon()        // override 
  771. {
  772.     CSectionIterator iter(this);
  773.     
  774.     for (TSection* aSection = iter.FirstSection(); iter.More(); aSection = iter.NextSection())
  775.         if (aSection->GetSectionType() == stPublisher)
  776.         {
  777.             // if publisher is *new* and it hasn't been saved yet,
  778.             // delete the edition container file 
  779.             if (((TPublisher*)aSection)->fNewSection)
  780.                 ((TPublisher*)aSection)->DeleteEditionFile();
  781.         }
  782.     
  783.     fNewPublishers = FALSE;                        // no new publishers any more
  784.  
  785.     Inherited::Abandon();
  786. } // TEditionDocument::Abandon 
  787.  
  788. //----------------------------------------------------------------------------------------
  789. // TEditionDocument::DoNeedDiskSpace: 
  790. //----------------------------------------------------------------------------------------
  791. #pragma segment MAWriteFile
  792.  
  793. void TEditionDocument::DoNeedDiskSpace(TFile* itsFile,
  794.                                        long& dataForkBytes,
  795.                                        long& rsrcForkBytes)
  796. {
  797.     Inherited::DoNeedDiskSpace(itsFile, dataForkBytes, rsrcForkBytes);
  798.  
  799.     rsrcForkBytes += kRsrcTypeOverhead + kRsrcOverhead +
  800.                         sizeof(EditionDocSettings) + strlen(kEditionDocRsrcName) + kLengthByte;
  801.  
  802.     CSectionIterator iter(this);
  803.     
  804.     // if there are any sections to write, add in type overhead for alis', 'sect', and 'DESG'
  805.     if (iter.More())
  806.         rsrcForkBytes += (3 * kRsrcTypeOverhead);
  807.  
  808.     for (TSection* aSection = iter.FirstSection(); iter.More(); aSection = iter.NextSection())
  809.         aSection->DoNeedDiskSpace(dataForkBytes, rsrcForkBytes);
  810.     
  811. } // TEditionDocument::DoNeedDiskSpace 
  812.  
  813. //----------------------------------------------------------------------------------------
  814. // TEditionDocument::DoAddSectionBehavior: 
  815. //----------------------------------------------------------------------------------------
  816. #pragma segment MAOpen
  817.  
  818. void TEditionDocument::DoAddSectionBehavior(TView* itsView)
  819. // a convenience method supplied for the convenience of the user
  820. {
  821.     if (itsView)
  822.     {
  823.         TBehavior* itsBehavior = itsView->GetBehaviorWithIdentifier(kSectionBehavior);
  824.         if (!itsBehavior)
  825.         {
  826.             TSectionBehavior* aSectionBehavior = new TSectionBehavior;
  827.             aSectionBehavior->ISectionBehavior(kSectionBehavior);
  828.             itsView->AddBehavior(aSectionBehavior);
  829.         }
  830.     }
  831. } // TEditionDocument::DoAddSectionBehavior 
  832.  
  833. //----------------------------------------------------------------------------------------
  834. // TEditionDocument::DoNewPublisher: 
  835. //----------------------------------------------------------------------------------------
  836. #pragma segment MADocumentNonRes
  837.  
  838. void TEditionDocument::DoNewPublisher()
  839.  
  840. {
  841.     OSErr err;
  842.     TDesignator * itsDesignator;
  843.     
  844.     //MAVolatile(NewPublisherReply, reply);
  845.     NewPublisherReply reply;    // can't be volatile because it is passed by reference
  846.  
  847.     // set up the reply record 
  848.     err = GetLastEditionContainerUsed(&(reply.container));
  849.     if ((err != noErr) && (err != fnfErr))        // allow fnfErr 
  850.         FailOSErr(err);
  851.     this->GetNextEditionName(*((CStr63 *) reply.container.theFile.name));
  852.     reply.usePart = FALSE;                        // always set this to false 
  853.  
  854.     // create the preview 
  855.     itsDesignator = this->GetUserSelection();
  856.     FailNIL(itsDesignator);
  857.  
  858.     this->DoMakePreview(itsDesignator, reply.previewFormat, reply.preview);
  859.  
  860.     FailInfo fi;
  861.     Try(fi)
  862.     {
  863.         this->DoNewPublisherDialog(reply);            // query the user 
  864.         fi.Success();
  865.     }
  866.     else
  867.     {
  868.         this->DisposeOfPreview(reply);
  869.         fi.ReSignal();
  870.     }
  871.     
  872.     this->DisposeOfPreview(reply);
  873.  
  874.     if (!reply.canceled)
  875.     {
  876.         FSSpec aFSSpec;
  877.         FSSpecPtr aFSSpecPtr;
  878.  
  879.         if (!reply.replacing)
  880.             FailOSErr(CreateEditionContainerFile(&(reply.container.theFile), this->GetEditionCreatorSignature(), reply.container.theFileScript));
  881.  
  882.         FailInfo fi;
  883.         Try(fi)
  884.         {
  885.             //MAVolatileInit(SectionHandle, sectionH, NULL);
  886.             SectionHandle sectionH = NULL;    // can't be volatile because it is passed by reference
  887.             MAVolatileInit(TPublisher*, aPublisher, NULL);
  888.             MAVolatileInit(TDesignator*, newDesignator, NULL);
  889.     
  890.             // Prepare for call to NewSection
  891.             short newSectionID = this->GetUniqueSectRsrcID();
  892.     
  893.             aFSSpecPtr = NULL;                        // can pass in NULL to NewSection 
  894.             TFile* aFile = this->GetFile();
  895.             if (aFile && (aFile->HasValidFileSpec()))
  896.             {
  897.                 aFile->GetFileSpec(aFSSpec);
  898.                 aFSSpecPtr = &aFSSpec;
  899.             }
  900.     
  901.             // Call NewSection (which calls RegisterSection for us)
  902.             err = NewSection(&(reply.container), aFSSpecPtr, stPublisher, newSectionID, pumOnSave, §ionH);
  903.             if ((err != noErr) && (err != multiplePublisherWrn) && (err != notThePublisherWrn))
  904.                 FailOSErr(err);
  905.     
  906.             FailInfo innerfi;
  907.             Try(innerfi)
  908.             {
  909.                 // publisher owns its designator -- so clone it
  910.                 newDesignator = (TDesignator *)itsDesignator->Clone();
  911.         
  912.                 // Create the publisher object, add it to our list of sections,
  913.                 // mark it as changed, and publish it to disk.
  914.                 
  915.                 aPublisher = this->DoMakePublisher(newDesignator, sectionH, newSectionID);
  916.                 if ((err == multiplePublisherWrn) || (err == notThePublisherWrn))
  917.                     this->PoseMultPublishersAlert(aPublisher);
  918.         
  919.                 this->AddSectionAndBorder(aPublisher);
  920.                 aPublisher->MarkAsChanged();
  921.                 aPublisher->Publish(aFile);
  922.                 
  923.                 innerfi.Success();
  924.             }
  925.             else // Recover
  926.             {
  927.                 if (aPublisher)
  928.                     aPublisher = (TPublisher *)(FreeIfObject(aPublisher));
  929.                 else
  930.                 {
  931.                     newDesignator = (TDesignator *)(FreeIfObject(newDesignator));
  932.                     if (sectionH && (IsRegisteredSection(sectionH) == noErr))
  933.                         UnRegisterSection(sectionH);    // Ignore the warnings.
  934.                 }
  935.                 innerfi.ReSignal();
  936.             }
  937.  
  938.             fi.Success();
  939.         }
  940.         else // Recover
  941.         {
  942.             err = DeleteEditionContainerFile(&(reply.container.theFile));
  943.             fi.ReSignal();
  944.         }
  945.  
  946.         // let the edition document know that there is a new publisher 
  947.         fNewPublishers = TRUE;
  948.     }
  949. } // TEditionDocument::DoNewPublisher 
  950.  
  951. //----------------------------------------------------------------------------------------
  952. // TEditionDocument::DoMakePreview: 
  953. //----------------------------------------------------------------------------------------
  954. #pragma segment MADocumentNonRes
  955.  
  956. void TEditionDocument::DoMakePreview(TDesignator* itsDesignator,
  957.                                      FormatType& previewFormat,
  958.                                      Handle& preview)
  959. {
  960.     MAVolatileInit(Handle&, volatilePreview, preview);
  961.     volatilePreview = NULL;
  962.  
  963.     previewFormat = this->GetPublishPreference();
  964.     if ((previewFormat == 'TEXT') || (previewFormat == 'PICT') || (previewFormat == 'snd '))
  965.     {
  966.         MAVolatileInit(THandleStream*, aHandleStream, NULL);
  967.  
  968.         volatilePreview = NewPermHandle(0);
  969.  
  970.         FailInfo fi;
  971.         Try(fi)
  972.         {
  973.             aHandleStream = new THandleStream;
  974.             aHandleStream->IHandleStream(volatilePreview, 6);
  975.             
  976.             FailInfo innerfi;
  977.             Try(innerfi)
  978.             {
  979.                 this->DoWriteData(previewFormat, itsDesignator, aHandleStream);
  980.                 innerfi.Success();
  981.             }
  982.             else // Recover
  983.             {
  984.                 volatilePreview = DisposeIfHandle(volatilePreview);
  985.                 aHandleStream = (THandleStream*)FreeIfObject(aHandleStream);
  986.                 innerfi.ReSignal();
  987.             }
  988.             aHandleStream = (THandleStream*)FreeIfObject(aHandleStream);
  989.             fi.Success();
  990.         }
  991.         else    // Recover
  992.         {
  993.             volatilePreview = DisposeIfHandle(volatilePreview);
  994.             fi.ReSignal();
  995.         }
  996.     }
  997. } // TEditionDocument::DoMakePreview 
  998.  
  999. //----------------------------------------------------------------------------------------
  1000. // TEditionDocument::DisposeOfPreview: 
  1001. //----------------------------------------------------------------------------------------
  1002. #pragma segment MADocumentNonRes
  1003.  
  1004. void TEditionDocument::DisposeOfPreview(NewPublisherReply& reply)
  1005. {
  1006.     if (reply.previewFormat == 'PICT')
  1007.         reply.preview = (Handle)DisposeIfPicHandle((PicHandle) reply.preview);
  1008.     else if (reply.previewFormat == 'TEXT')
  1009.         reply.preview = DisposeIfHandle(reply.preview);
  1010. } // TEditionDocument::DisposeOfPreview 
  1011.  
  1012. //----------------------------------------------------------------------------------------
  1013. // TEditionDocument::GetEditionCreatorSignature: 
  1014. //----------------------------------------------------------------------------------------
  1015. #pragma segment MADocumentNonRes
  1016.  
  1017. OSType TEditionDocument::GetEditionCreatorSignature()
  1018.  
  1019. {
  1020.     return fEditionCreator;
  1021. } // TEditionDocument::GetEditionCreatorSignature 
  1022.  
  1023. //----------------------------------------------------------------------------------------
  1024. // TEditionDocument::GetPublishPreference: 
  1025. //----------------------------------------------------------------------------------------
  1026. #pragma segment MADocumentNonRes
  1027.  
  1028. FormatType TEditionDocument::GetPublishPreference()
  1029.  
  1030. {
  1031.     return ((long)'TEXT');                        // by default, prefer to publish 'TEXT'
  1032.                                                 // over 'PICT'
  1033. } // TEditionDocument::GetPublishPreference 
  1034.  
  1035. //----------------------------------------------------------------------------------------
  1036. // TEditionDocument::DoMakePublisher: 
  1037. //----------------------------------------------------------------------------------------
  1038. #pragma segment MADocumentNonRes
  1039.  
  1040. TPublisher* TEditionDocument::DoMakePublisher(TDesignator* itsDesignator,
  1041.                                               SectionHandle itsSectionHandle,
  1042.                                               short itsSectionID)
  1043. {
  1044.     TPublisher * aPublisher = new TPublisher;    // create a TPublisher object 
  1045.     aPublisher->IPublisher(this, itsDesignator, itsSectionHandle, itsSectionID);
  1046.     return aPublisher;
  1047. } // TEditionDocument::DoMakePublisher 
  1048.  
  1049. //----------------------------------------------------------------------------------------
  1050. // TEditionDocument::DoNewPublisherDialog: 
  1051. //----------------------------------------------------------------------------------------
  1052. #pragma segment MADocumentNonRes
  1053.  
  1054. void TEditionDocument::DoNewPublisherDialog(NewPublisherReply& reply)
  1055.  
  1056. {
  1057.     // override this method if you decide to use the NewPublisherExpDialog instead 
  1058.     FailOSErr(MAInteractWithUser()); 
  1059.  
  1060.     gClipboardMgr->AboutToLoseControl(TRUE);    // so scrap gets converted
  1061.     FailOSErr(NewPublisherDialog(&reply));
  1062.     gClipboardMgr->RegainControl(TRUE);            // so scrap gets converted
  1063. } // TEditionDocument::DoNewPublisherDialog 
  1064.  
  1065. //----------------------------------------------------------------------------------------
  1066. // TEditionDocument::DoNewSubscriber: 
  1067. //----------------------------------------------------------------------------------------
  1068. #pragma segment MADocumentNonRes
  1069.  
  1070. void TEditionDocument::DoNewSubscriber()
  1071.  
  1072. {
  1073.     OSErr err;
  1074.     NewSubscriberReply reply;
  1075.     short newSectionID;
  1076.     FSSpec aFSSpec;
  1077.     FSSpecPtr aFSSpecPtr;
  1078.     SectionHandle sectionH;
  1079.     TSubscriber * aSubscriber;
  1080.     TDesignator * aDesignator;
  1081.  
  1082.     err = GetLastEditionContainerUsed(&(reply.container));// fill in the reply 
  1083.     if ((err != noErr) && (err != fnfErr))        // allow fnfErr 
  1084.         FailOSErr(err);
  1085.     reply.formatsMask = this->GetSubscriberFormatsMask();// set up the formatsMask 
  1086.     this->DoNewSubscriberDialog(reply);
  1087.     if (!reply.canceled)
  1088.     {
  1089.         newSectionID = this->GetUniqueSectRsrcID();
  1090.         // create a new section handle 
  1091.         aFSSpecPtr = NULL;
  1092.         TFile* aFile = this->GetFile();
  1093.         if (aFile && (aFile->HasValidFileSpec()))
  1094.         {
  1095.             aFile->GetFileSpec(aFSSpec);
  1096.             aFSSpecPtr = &aFSSpec;
  1097.         }
  1098.         FailOSErr(NewSection(&(reply.container), aFSSpecPtr, stSubscriber, newSectionID, sumAutomatic, §ionH));
  1099.         // NewSection calls RegisterSection for us 
  1100.  
  1101.         // create a TDesignator for the TSubscriber object 
  1102.         aDesignator = this->GetUserSelection();
  1103.         if (aDesignator)
  1104.             aDesignator = (TDesignator *)aDesignator->Clone();// the subscriber owns the designator
  1105.  
  1106.         // create a TSubscriber object, add it to our list of sections, and mark it as changed
  1107.         aSubscriber = this->DoMakeSubscriber(aDesignator, sectionH, newSectionID);
  1108.         this->AddSectionAndBorder(aSubscriber);
  1109.         aSubscriber->MarkAsChanged();
  1110.     }
  1111. } // TEditionDocument::DoNewSubscriber 
  1112.  
  1113. //----------------------------------------------------------------------------------------
  1114. // TEditionDocument::DoMakeSubscriber: 
  1115. //----------------------------------------------------------------------------------------
  1116. #pragma segment MADocumentNonRes
  1117.  
  1118. TSubscriber* TEditionDocument::DoMakeSubscriber(TDesignator* itsDesignator,
  1119.                                                 SectionHandle itsSectionHandle,
  1120.                                                 short itsSectionID)
  1121. {
  1122.     // create and return a TSubscriber object 
  1123.     TSubscriber * aSubscriber = new TSubscriber;
  1124.     aSubscriber->ISubscriber(this, itsDesignator, itsSectionHandle, itsSectionID);
  1125.     return aSubscriber;
  1126. } // TEditionDocument::DoMakeSubscriber 
  1127.  
  1128. //----------------------------------------------------------------------------------------
  1129. // TEditionDocument::DoNewSubscriberDialog: 
  1130. //----------------------------------------------------------------------------------------
  1131. #pragma segment MADocumentNonRes
  1132.  
  1133. void TEditionDocument::DoNewSubscriberDialog(NewSubscriberReply& reply)
  1134.  
  1135. {
  1136.     // override this method if you decide to use the NewSubscriberExpDialog instead 
  1137.     FailOSErr(MAInteractWithUser()); 
  1138.  
  1139.     gClipboardMgr->AboutToLoseControl(TRUE);        // so scrap gets converted
  1140.     FailOSErr(NewSubscriberDialog(&reply));        // pose the new subscriber dialog 
  1141.     gClipboardMgr->RegainControl(TRUE);            // so scrap gets converted
  1142. } // TEditionDocument::DoNewSubscriberDialog 
  1143.  
  1144. //----------------------------------------------------------------------------------------
  1145. // TEditionDocument::DoPublisherOptions: 
  1146. //----------------------------------------------------------------------------------------
  1147. #pragma segment MADocumentNonRes
  1148.  
  1149. void TEditionDocument::DoPublisherOptions(TPublisher* aPublisher)
  1150.  
  1151. {
  1152.     SectionOptionsReply reply;
  1153.  
  1154.     reply.sectionH = aPublisher->fSectionHandle;
  1155.     this->DoPublisherOptionsDialog(reply);
  1156.     if (!reply.canceled)
  1157.     {
  1158.         if (reply.changed)
  1159.             aPublisher->MarkAsChanged();
  1160.  
  1161.         if (reply.action == sectionWriteMsgID)
  1162.         {
  1163.             TFile* aFile = this->GetFile();
  1164.             aPublisher->Publish(aFile);
  1165.         }
  1166.         else if (reply.action == sectionCancelMsgID)
  1167.         {
  1168.             TSectionCancelEventCommand * aSectionCancelEventCommand = new TSectionCancelEventCommand;
  1169.             aSectionCancelEventCommand->ISectionCancelEventCommand(cCancelPublisher, this, aPublisher);
  1170.             this->PostCommand(aSectionCancelEventCommand);
  1171.         }
  1172.     }
  1173. } // TEditionDocument::DoPublisherOptions 
  1174.  
  1175. //----------------------------------------------------------------------------------------
  1176. // TEditionDocument::DoPublisherOptionsDialog: 
  1177. //----------------------------------------------------------------------------------------
  1178. #pragma segment MADocumentNonRes
  1179.  
  1180. void TEditionDocument::DoPublisherOptionsDialog(SectionOptionsReply& reply)
  1181.  
  1182. {
  1183.     // override this method if you decide to use the SectionOptionsExpDialog instead 
  1184.     FailOSErr(MAInteractWithUser()); 
  1185.  
  1186.     gClipboardMgr->AboutToLoseControl(TRUE);        // so scrap gets converted
  1187.     FailOSErr(SectionOptionsDialog(&reply));
  1188.     gClipboardMgr->RegainControl(TRUE);            // so scrap gets converted
  1189. } // TEditionDocument::DoPublisherOptionsDialog 
  1190.  
  1191. //----------------------------------------------------------------------------------------
  1192. // TEditionDocument::DoSubscriberOptions: 
  1193. //----------------------------------------------------------------------------------------
  1194. #pragma segment MADocumentNonRes
  1195.  
  1196. void TEditionDocument::DoSubscriberOptions(TSubscriber* aSubscriber)
  1197.  
  1198. {
  1199.     SectionOptionsReply reply;
  1200.  
  1201.     reply.sectionH = aSubscriber->fSectionHandle;
  1202.     this->DoSubscriberOptionsDialog(reply);
  1203.     if (!reply.canceled)
  1204.     {
  1205.         if (reply.changed)
  1206.             aSubscriber->MarkAsChanged();
  1207.  
  1208.         if (reply.action == sectionReadMsgID)
  1209.             aSubscriber->Subscribe();
  1210.         else if (reply.action == 'goto')
  1211.             aSubscriber->OpenPublisher();
  1212.         else if (reply.action == sectionCancelMsgID)
  1213.         {
  1214.             TSectionCancelEventCommand * aSectionCancelEventCommand = new TSectionCancelEventCommand;
  1215.             aSectionCancelEventCommand->ISectionCancelEventCommand(cCancelSubscriber, this, aSubscriber);
  1216.             this->PostCommand(aSectionCancelEventCommand);
  1217.         }
  1218.     }
  1219. } // TEditionDocument::DoSubscriberOptions 
  1220.  
  1221. //----------------------------------------------------------------------------------------
  1222. // TEditionDocument::DoSubscriberOptionsDialog: 
  1223. //----------------------------------------------------------------------------------------
  1224. #pragma segment MADocumentNonRes
  1225.  
  1226. void TEditionDocument::DoSubscriberOptionsDialog(SectionOptionsReply& reply)
  1227.  
  1228. {
  1229.     // override this method if you decide to use the SectionOptionsExpDialog instead 
  1230.     FailOSErr(MAInteractWithUser()); 
  1231.  
  1232.     gClipboardMgr->AboutToLoseControl(TRUE);    // so scrap gets converted
  1233.     FailOSErr(SectionOptionsDialog(&reply));
  1234.     gClipboardMgr->RegainControl(TRUE);            // so scrap gets converted
  1235. } // TEditionDocument::DoSubscriberOptionsDialog 
  1236.  
  1237. //----------------------------------------------------------------------------------------
  1238. // TEditionDocument::DoSetupMenus: 
  1239. //----------------------------------------------------------------------------------------
  1240. #pragma segment MADocumentRes
  1241.  
  1242. void TEditionDocument::DoSetupMenus()            // override 
  1243.  
  1244. {
  1245.     Inherited::DoSetupMenus();
  1246.  
  1247.     if (fNewPublishers)                        // there are new publishers! 
  1248.     {
  1249.         Enable(cSave, TRUE);
  1250.         Enable(cRevert, TRUE);
  1251.     }
  1252.  
  1253.     Enable(cCreatePublisher, this->CanPublishSelection());
  1254.     Enable(cSubscribeTo, this->CanSubscribe());
  1255.  
  1256.     TSection * aSection = this->GetSelectedSection();
  1257.     if (aSection)
  1258.     {
  1259.         Enable(cOptions, TRUE);
  1260.         if (aSection->GetSectionType() == stPublisher)
  1261.             SetIndividualCommandName(cOptions, kIDBuzzString, bzPublisherOptions);
  1262.         else if (aSection->GetSectionType() == stSubscriber)
  1263.             SetIndividualCommandName(cOptions, kIDBuzzString, bzSubscriberOptions);
  1264. #if qDebug
  1265.         else
  1266.             ProgramBreak("what kind of section is it anyway?");
  1267. #endif
  1268.     }
  1269.  
  1270.     Enable(cBorders, TRUE);
  1271.     SetMenuState(cBorders, kIDBuzzString, bzShowBorders, bzHideBorders, fShowSectionBorders);
  1272.  
  1273.     EnableCheck(cStopAllEditions, TRUE, fStopAllEditions);
  1274. } // TEditionDocument::DoSetupMenus 
  1275.  
  1276. //----------------------------------------------------------------------------------------
  1277. // TEditionDocument::GetNextEditionName: 
  1278. //----------------------------------------------------------------------------------------
  1279. #pragma segment MADocumentNonRes
  1280.  
  1281. void TEditionDocument::GetNextEditionName(CStr63& editionName)
  1282.  
  1283. {
  1284.     CStr255 name;
  1285.     GetIndString(name, kIDBuzzString, bzUntitled);
  1286.  
  1287.     short preInsert;
  1288.     short constChars;
  1289.     if (ParseTitleTemplate(name, preInsert, constChars))
  1290.     {
  1291.         CStr255 numStr;
  1292.         NumToString(fNextEditionNumber, numStr);
  1293.         if (SubstituteInTitle(name, numStr, preInsert, constChars))
  1294.             ++fNextEditionNumber;
  1295.     }
  1296.  
  1297.     editionName = name;
  1298. } // TEditionDocument::GetNextEditionName 
  1299.  
  1300. //----------------------------------------------------------------------------------------
  1301. // TEditionDocument::GetSubscriberFormatsMask: 
  1302. //----------------------------------------------------------------------------------------
  1303. #pragma segment MADocumentNonRes
  1304.  
  1305. SignedByte TEditionDocument::GetSubscriberFormatsMask()
  1306.  
  1307. {
  1308.     // Return a mask corresponding to the edition format type to display within the
  1309.     // subscriber dialog box. This mask may consist of as many types as are supported in
  1310.     // the application. Construct the mask as follows:
  1311.     //  GetSubscriberFormatsMask = [kPICTformatMask] [+] [kTextformatMask [+] [ksndFormatMask]
  1312.  
  1313.     if (this->GetPublishPreference() == 'TEXT')
  1314.         return (kTEXTformatMask);
  1315.     else if (this->GetPublishPreference() == 'PICT')
  1316.         return (kPICTformatMask);
  1317.     else if (this->GetPublishPreference() == 'snd ')
  1318.         return (ksndFormatMask);
  1319.     
  1320.     return 0;
  1321. } // TEditionDocument::GetSubscriberFormatsMask 
  1322.  
  1323. //----------------------------------------------------------------------------------------
  1324. // TEditionDocument::GetUniqueSectRsrcID: 
  1325. //----------------------------------------------------------------------------------------
  1326. #pragma segment MADocumentNonRes
  1327.  
  1328. const short kFirstRsrcID = 1000;
  1329. const short kLastRsrcID = 32767;
  1330. const short kBitsInArray = kLastRsrcID - kFirstRsrcID;
  1331.  
  1332. short TEditionDocument::GetUniqueSectRsrcID()
  1333. {
  1334.     short counter = 0;
  1335.     Size arraySize = (kBitsInArray / sizeof(Byte)) + 1;
  1336.     Ptr aPtr = NewPermPtr(arraySize);
  1337.     Boolean foundNewID;
  1338.  
  1339.     BlockSet(aPtr, arraySize, 0x00);            // zero it out
  1340.     
  1341.     CSectionIterator iter(this);
  1342.  
  1343.     for (TSection* aSection = iter.FirstSection(); iter.More(); aSection = iter.NextSection())
  1344.     {
  1345.         short itsRsrcID = aSection->fRsrcID;
  1346.         
  1347.         if (itsRsrcID >= kFirstRsrcID)
  1348.             BitSet(aPtr, itsRsrcID - kFirstRsrcID);
  1349.         else
  1350.         {
  1351. #if qDebug
  1352.             ProgramBreak("problem with section rsrc id");
  1353. #endif
  1354.         }
  1355.     }
  1356.  
  1357.     while (BitTst(aPtr, counter) && (counter < kBitsInArray))
  1358.         ++counter;
  1359.  
  1360.     foundNewID =!BitTst(aPtr, counter);            // see if we got a new rsrc id 
  1361.  
  1362.     aPtr = DisposeIfPtr(aPtr);                    // dispose of the array 
  1363.  
  1364.     if (!foundNewID)
  1365.         Failure(minErr, 0);
  1366.  
  1367.     return (counter + kFirstRsrcID);            // return the new sect rsrc id 
  1368. } // TEditionDocument::GetUniqueSectRsrcID 
  1369.  
  1370. //----------------------------------------------------------------------------------------
  1371. // TEditionDocument::DoPostMakeViews: 
  1372. //----------------------------------------------------------------------------------------
  1373. #pragma segment MAOpen
  1374.  
  1375. void TEditionDocument::DoPostMakeViews(Boolean forPrinting)
  1376. {
  1377.     // The case that we're concerned with here is the TApplication::OpenOld case, in which
  1378.     // our DoRead method will get called before there are any views. This method provides
  1379.     // a way for borders to be added to views "after the fact" to handle the OpenOld case.
  1380.     // The document will have been read in (DoRead), the views created (DoMakeViews) and
  1381.     // finally the post create method called (DoPostMakeViews) at which point the borders
  1382.     // can then be safely added.
  1383.  
  1384.     if (!forPrinting)
  1385.     {
  1386.         CSectionIterator iter(this);
  1387.     
  1388.         for (TSection* aSection = iter.FirstSection(); iter.More(); aSection = iter.NextSection())
  1389.             this->DoAddBorder(aSection);
  1390.     }
  1391.  
  1392.     Inherited::DoPostMakeViews(forPrinting);
  1393. } // TEditionDocument::DoPostMakeViews 
  1394.  
  1395. //----------------------------------------------------------------------------------------
  1396. // TEditionDocument::DoAddBorder: 
  1397. //----------------------------------------------------------------------------------------
  1398. #pragma segment MADocumentNonRes
  1399.  
  1400. void TEditionDocument::DoAddBorder(TSection* /* aSection */)
  1401.  
  1402. {
  1403.     // subclasses should override this to create a border to adorn this section
  1404. } // TEditionDocument::DoAddBorder 
  1405.  
  1406. //----------------------------------------------------------------------------------------
  1407. // TEditionDocument::DoAdjustBorder: 
  1408. //----------------------------------------------------------------------------------------
  1409. #pragma segment MADocumentNonRes
  1410.  
  1411. void TEditionDocument::DoAdjustBorder(TSection* /* aSection */)
  1412.  
  1413. {
  1414.     // subclasses should override this to create a border to adorn this section
  1415. } // TEditionDocument::DoAdjustBorder 
  1416.  
  1417. //----------------------------------------------------------------------------------------
  1418. // TEditionDocument::DoDeleteBorder: 
  1419. //----------------------------------------------------------------------------------------
  1420. #pragma segment MADocumentNonRes
  1421.  
  1422. void TEditionDocument::DoDeleteBorder(TSection* /* aSection */)
  1423.  
  1424. {
  1425.     // subclasses should override this to remove the border adorning this section
  1426. } // TEditionDocument::DoDeleteBorder 
  1427.  
  1428. //----------------------------------------------------------------------------------------
  1429. // TEditionDocument::IsBorderShown: 
  1430. //----------------------------------------------------------------------------------------
  1431. #pragma segment MADocumentRes
  1432.  
  1433. Boolean TEditionDocument::IsBorderShown(TSection* aSection)
  1434.  
  1435. {
  1436.     if (!aSection->IsCanceled())
  1437.         return (fShowSectionBorders || (this->GetSelectedSection() == aSection));
  1438.     else
  1439.         return FALSE;
  1440. } // TEditionDocument::IsBorderShown 
  1441.  
  1442. //----------------------------------------------------------------------------------------
  1443. // TEditionDocument::IsSectionSelected: 
  1444. //----------------------------------------------------------------------------------------
  1445. #pragma segment MADocumentNonRes
  1446.  
  1447. Boolean TEditionDocument::IsSectionSelected(TSection* aSection)
  1448. // !!! should really be called TEditionDocument::IsSectionInSelection
  1449. {
  1450.     if (aSection && !aSection->IsCanceled() && aSection->fDesignator)
  1451.     {
  1452.         TDesignator* userSelection = this->GetUserSelection();
  1453.         if (userSelection)
  1454.             return (userSelection->IsContained(aSection->fDesignator) != kNotContained);
  1455.         else
  1456.             return (FALSE);
  1457.     }
  1458.     else
  1459.         return (FALSE);
  1460. } // TEditionDocument::IsSectionSelected 
  1461.  
  1462. //----------------------------------------------------------------------------------------
  1463. // TEditionDocument::AddSection: 
  1464. //----------------------------------------------------------------------------------------
  1465. #pragma segment MADocumentNonRes
  1466.  
  1467. void TEditionDocument::AddSection(TSection* aSection)
  1468.  
  1469. {
  1470.     // Protect against double installation 
  1471.     if (fSectionList)
  1472.     {
  1473.         if (fSectionList->GetIdentityItemNo(aSection) == 0)// doesn't already exist in list 
  1474.             fSectionList->Insert(aSection);
  1475.     }
  1476. #if qDebug
  1477.     else
  1478.         ProgramBreak("fSectionList is NULL");
  1479. #endif
  1480.     
  1481.     // add the section to the section mgr's list of registered sections
  1482.     TSectionMgr* aSectionMgr =
  1483.         (TSectionMgr*) gDispatcher->GetBehaviorWithIdentifier(kSectionMgrBehaviorID);
  1484.     if (aSectionMgr)
  1485.         aSectionMgr->fSectionList->Insert(aSection);
  1486. } // TEditionDocument::AddSection 
  1487.  
  1488. //----------------------------------------------------------------------------------------
  1489. // TEditionDocument::AddSectionAndBorder: 
  1490. //----------------------------------------------------------------------------------------
  1491. #pragma segment MADocumentNonRes
  1492.  
  1493. void TEditionDocument::AddSectionAndBorder(TSection* aSection)
  1494.  
  1495. {
  1496.     this->AddSection(aSection);
  1497.     // notify the document to create a border for this section
  1498.     this->DoAddBorder(aSection);
  1499. } // TEditionDocument::AddSectionAndBorder 
  1500.  
  1501. //----------------------------------------------------------------------------------------
  1502. // TEditionDocument::RemoveSection: 
  1503. //----------------------------------------------------------------------------------------
  1504. #pragma segment MADocumentNonRes
  1505.  
  1506. void TEditionDocument::RemoveSection(TSection* aSection)
  1507.  
  1508. {
  1509.     if (fSectionList)
  1510.         fSectionList->Delete(aSection);
  1511. #if qDebug
  1512.     else
  1513.         ProgramBreak("fSectionList is NULL");
  1514. #endif
  1515.  
  1516.     // add the section to the section mgr's list of registered sections
  1517.     TSectionMgr* aSectionMgr =
  1518.         (TSectionMgr*) gDispatcher->GetBehaviorWithIdentifier(kSectionMgrBehaviorID);
  1519.     if (aSectionMgr)
  1520.         aSectionMgr->fSectionList->Delete(aSection);
  1521. } // TEditionDocument::RemoveSection 
  1522.  
  1523. //----------------------------------------------------------------------------------------
  1524. // TEditionDocument::CancelSection: 
  1525. //----------------------------------------------------------------------------------------
  1526. #pragma segment MADocumentNonRes
  1527.  
  1528. void TEditionDocument::CancelSection(TSection* aSection, Boolean cancel)
  1529. {
  1530.     aSection->CancelSection(cancel);
  1531.     
  1532.     // notify the document to add or delete a border for this section
  1533.     if (cancel)
  1534.         this->DoDeleteBorder(aSection);
  1535.     else
  1536.         this->DoAddBorder(aSection);
  1537. } // TEditionDocument::CancelSection 
  1538.  
  1539. //----------------------------------------------------------------------------------------
  1540. // TEditionDocument::GetSelectedSection: 
  1541. //----------------------------------------------------------------------------------------
  1542. #pragma segment MADocumentNonRes
  1543.  
  1544. TSection* TEditionDocument::GetSelectedSection()
  1545. {
  1546.     TSection* selectedSection = NULL;
  1547.  
  1548.     CSectionIterator iter(this);
  1549.     for (TSection* aSection = iter.FirstSection(); iter.More(); aSection = iter.NextSection())
  1550.         if (this->IsSectionSelected(aSection))
  1551.             if (!selectedSection)
  1552.                 selectedSection = aSection;
  1553.             else
  1554.             {    // in this case, >1 sections are in the user selection, so need to
  1555.                 // determine which section is the preferred selected section
  1556.                 if (aSection->fDesignator->GetSize() < selectedSection->fDesignator->GetSize())
  1557.                     selectedSection = aSection;
  1558.             }
  1559.     
  1560.     return selectedSection;
  1561. } // TEditionDocument::GetSelectedSection 
  1562.  
  1563. //----------------------------------------------------------------------------------------
  1564. // TEditionDocument::SetSectionBorders: 
  1565. //----------------------------------------------------------------------------------------
  1566. #pragma segment MADocumentNonRes
  1567.  
  1568. void TEditionDocument::SetSectionBorders(Boolean state, Boolean invalidate)
  1569. {
  1570.     if (fShowSectionBorders != state)
  1571.     {
  1572.         fShowSectionBorders = state;
  1573.  
  1574.         if (invalidate)
  1575.         {
  1576.             CWindowIterator iter(this);
  1577.         
  1578.             for (TWindow* aWindow = iter.FirstWindow(); iter.More(); aWindow = iter.NextWindow())
  1579.                 aWindow->ForceRedraw();
  1580.         }
  1581.     }
  1582.     // This could be a lot smarter if we had a reference to the view that had the borders.
  1583.     // Something like the following could be done instead:
  1584.     //        CAdornerIterator iter(fViewWithBorders);
  1585.     //        for (TAdorner * anAdorner = iter.FirstAdorner(); iter.More(); anAdorner = iter.NextAdorner())
  1586.     //            if ((anAdorner->fIdentifier == kPublisherAdornerID)
  1587.     //                || (anAdorner->fIdentifier == kSubscriberAdornerID))
  1588.     //                anAdorner->InvalidateAdorner(fCellsView);
  1589. } // TEditionDocument::SetSectionBorders 
  1590.  
  1591. //----------------------------------------------------------------------------------------
  1592. // TEditionDocument::SetStopAllEditions: 
  1593. //----------------------------------------------------------------------------------------
  1594. #pragma segment MADocumentNonRes
  1595.  
  1596. void TEditionDocument::SetStopAllEditions(Boolean state)
  1597. {
  1598.     if (fStopAllEditions != state)
  1599.     {
  1600.         fStopAllEditions = state;
  1601.         if (!state)                                // if turning "off" stop editions 
  1602.         {
  1603.             CSectionIterator iter(this);
  1604.             
  1605.             for (TSection* aSection = iter.FirstSection(); iter.More(); aSection = iter.NextSection())
  1606.                 if (aSection->GetSectionType() == stSubscriber)
  1607.                     ((TSubscriber*)aSection)->SubscribeIfNewer();
  1608.         }
  1609.     }
  1610. } // TEditionDocument::SetStopAllEditions 
  1611.  
  1612.  
  1613. //========================================================================================
  1614. // CLASS TNewSubscriberCommand
  1615. //========================================================================================
  1616. #undef Inherited
  1617. #define Inherited TCommand
  1618.  
  1619. #pragma segment MASelCommand
  1620. MA_DEFINE_CLASS_M1(TNewSubscriberCommand, Inherited);
  1621.  
  1622. //----------------------------------------------------------------------------------------
  1623. // TNewSubscriberCommand::TNewSubscriberCommand: Empty constructor to satisfy the compiler.
  1624. //----------------------------------------------------------------------------------------
  1625. #pragma segment ConstructorRes
  1626.  
  1627. TNewSubscriberCommand::TNewSubscriberCommand()
  1628. {
  1629. } // TNewSubscriberCommand::TNewSubscriberCommand
  1630.  
  1631. //----------------------------------------------------------------------------------------
  1632. // TNewSubscriberCommand destructor
  1633. //----------------------------------------------------------------------------------------
  1634. #pragma segment MADestructorRes
  1635.  
  1636. TNewSubscriberCommand::~TNewSubscriberCommand()
  1637. {
  1638. }
  1639.  
  1640. //----------------------------------------------------------------------------------------
  1641. // TNewSubscriberCommand::INewSubscriberCommand: 
  1642. //----------------------------------------------------------------------------------------
  1643. #pragma segment MACommandRes
  1644.  
  1645. void TNewSubscriberCommand::INewSubscriberCommand(CommandNumber itsCommandNumber,
  1646.                                                   TDocument* itsDocument)
  1647. {
  1648.     this->ICommand(itsCommandNumber, itsDocument, kCantUndo, kCausesChange, itsDocument);
  1649. } // TNewSubscriberCommand::INewSubscriberCommand 
  1650.  
  1651. //----------------------------------------------------------------------------------------
  1652. // TNewSubscriberCommand::DoIt: 
  1653. //----------------------------------------------------------------------------------------
  1654. #pragma segment MADoCommand
  1655.  
  1656. void TNewSubscriberCommand::DoIt()
  1657. {
  1658.     ((TEditionDocument*)fContext)->DoNewSubscriber();
  1659. } // TNewSubscriberCommand::DoIt 
  1660.  
  1661.  
  1662. //========================================================================================
  1663. // CLASS TSectionBorderCommand
  1664. //========================================================================================
  1665. #undef Inherited
  1666. #define Inherited TCommand
  1667.  
  1668. #pragma segment MASelCommand
  1669. MA_DEFINE_CLASS_M1(TSectionBorderCommand, Inherited);
  1670.  
  1671. //----------------------------------------------------------------------------------------
  1672. // TSectionBorderCommand::TSectionBorderCommand: Empty constructor to satisfy the compiler.
  1673. //----------------------------------------------------------------------------------------
  1674. #pragma segment ConstructorRes
  1675.  
  1676. TSectionBorderCommand::TSectionBorderCommand()
  1677. {
  1678. } // TSectionBorderCommand::TSectionBorderCommand
  1679.  
  1680. //----------------------------------------------------------------------------------------
  1681. // TSectionBorderCommand destructor
  1682. //----------------------------------------------------------------------------------------
  1683. #pragma segment MADestructorRes
  1684.  
  1685. TSectionBorderCommand::~TSectionBorderCommand()
  1686. {
  1687. }
  1688.  
  1689. //----------------------------------------------------------------------------------------
  1690. // TSectionBorderCommand::ISectionBorderCommand: 
  1691. //----------------------------------------------------------------------------------------
  1692. #pragma segment MACommandRes
  1693.  
  1694. void TSectionBorderCommand::ISectionBorderCommand(CommandNumber itsCommandNumber,
  1695.                                                   TDocument* itsDocument)
  1696. {
  1697.     this->ICommand(itsCommandNumber, itsDocument->GetContext(itsCommandNumber), kCanUndo, kCausesChange, itsDocument);
  1698.  
  1699.     fShowSectionBorders =!((TEditionDocument *)itsDocument)->fShowSectionBorders;
  1700. } // TSectionBorderCommand::ISectionBorderCommand 
  1701.  
  1702. //----------------------------------------------------------------------------------------
  1703. // TSectionBorderCommand::DoIt: 
  1704. //----------------------------------------------------------------------------------------
  1705. #pragma segment MADoCommand
  1706.  
  1707. void TSectionBorderCommand::DoIt()
  1708.  
  1709. {
  1710.     ((TEditionDocument *)fContext)->SetSectionBorders(fShowSectionBorders, kInvalidate);
  1711. } // TSectionBorderCommand::DoIt 
  1712.  
  1713. //----------------------------------------------------------------------------------------
  1714. // TSectionBorderCommand::UndoIt: 
  1715. //----------------------------------------------------------------------------------------
  1716. #pragma segment MADoCommand
  1717.  
  1718. void TSectionBorderCommand::UndoIt()
  1719.  
  1720. {
  1721.     ((TEditionDocument *)fContext)->SetSectionBorders(!fShowSectionBorders, kInvalidate);
  1722. } // TSectionBorderCommand::UndoIt 
  1723.  
  1724.  
  1725. //========================================================================================
  1726. // CLASS TStopAllEditionsCommand
  1727. //========================================================================================
  1728. #undef Inherited
  1729. #define Inherited TCommand
  1730.  
  1731. #pragma segment MASelCommand
  1732. MA_DEFINE_CLASS_M1(TStopAllEditionsCommand, Inherited);
  1733.  
  1734. //----------------------------------------------------------------------------------------
  1735. // TStopAllEditionsCommand::TStopAllEditionsCommand: Empty constructor to satisfy the compiler.
  1736. //----------------------------------------------------------------------------------------
  1737. #pragma segment ConstructorRes
  1738.  
  1739. TStopAllEditionsCommand::TStopAllEditionsCommand()
  1740. {
  1741. } // TStopAllEditionsCommand::TStopAllEditionsCommand
  1742.  
  1743. //----------------------------------------------------------------------------------------
  1744. // TStopAllEditionsCommand destructor
  1745. //----------------------------------------------------------------------------------------
  1746. #pragma segment MADestructorRes
  1747.  
  1748. TStopAllEditionsCommand::~TStopAllEditionsCommand()
  1749. {
  1750. }
  1751.  
  1752. //----------------------------------------------------------------------------------------
  1753. // TStopAllEditionsCommand::IStopAllEditionsCommand: 
  1754. //----------------------------------------------------------------------------------------
  1755. #pragma segment MACommandRes
  1756.  
  1757. void TStopAllEditionsCommand::IStopAllEditionsCommand(CommandNumber itsCommandNumber,
  1758.                                                       TDocument* itsDocument)
  1759.  
  1760. {
  1761.     this->ICommand(itsCommandNumber, itsDocument->GetContext(itsCommandNumber), kCanUndo, kCausesChange, itsDocument);
  1762.  
  1763.     fStopAllEditions =!((TEditionDocument *)itsDocument)->fStopAllEditions;
  1764. } // TStopAllEditionsCommand::IStopAllEditionsCommand 
  1765.  
  1766. //----------------------------------------------------------------------------------------
  1767. // TStopAllEditionsCommand::DoIt: 
  1768. //----------------------------------------------------------------------------------------
  1769. #pragma segment MADoCommand
  1770.  
  1771. void TStopAllEditionsCommand::DoIt()
  1772.  
  1773. {
  1774.     ((TEditionDocument *)fContext)->SetStopAllEditions(fStopAllEditions);
  1775. } // TStopAllEditionsCommand::DoIt 
  1776.  
  1777. //----------------------------------------------------------------------------------------
  1778. // TStopAllEditionsCommand::UndoIt: 
  1779. //----------------------------------------------------------------------------------------
  1780. #pragma segment MADoCommand
  1781.  
  1782. void TStopAllEditionsCommand::UndoIt()
  1783.  
  1784. {
  1785.     ((TEditionDocument *)fContext)->SetStopAllEditions(!fStopAllEditions);
  1786. } // TStopAllEditionsCommand::UndoIt 
  1787.  
  1788.  
  1789. //========================================================================================
  1790. // CLASS TSectionAdorner
  1791. //========================================================================================
  1792. #undef Inherited
  1793. #define Inherited TAdorner
  1794.  
  1795. #pragma segment MASelCommand
  1796. MA_DEFINE_CLASS_M1(TSectionAdorner, Inherited);
  1797.  
  1798. //----------------------------------------------------------------------------------------
  1799. // TSectionAdorner constructor
  1800. //----------------------------------------------------------------------------------------
  1801. #pragma segment MAAdornerNonRes
  1802.  
  1803. TSectionAdorner::TSectionAdorner()
  1804. {
  1805.     fSection = NULL;
  1806.     fBorderRegion = NULL;
  1807. } // TSectionAdorner::TSectionAdorner
  1808.  
  1809. //----------------------------------------------------------------------------------------
  1810. // TSectionAdorner::ISectionAdorner: 
  1811. //----------------------------------------------------------------------------------------
  1812. #pragma segment MAAdornerNonRes
  1813.  
  1814. void TSectionAdorner::ISectionAdorner(IDType itsID,
  1815.                                       TSection* itsSection,
  1816.                                       RgnHandle itsBorderRegion)
  1817. {
  1818.     this->IAdorner(itsID,kFreeOnDeletion);
  1819.  
  1820.     fSection = itsSection;
  1821.     fBorderRegion = itsBorderRegion;
  1822. } // TSectionAdorner::ISectionAdorner 
  1823.  
  1824. //----------------------------------------------------------------------------------------
  1825. // TSectionAdorner::Free: 
  1826. //----------------------------------------------------------------------------------------
  1827. #pragma segment MAAdornerNonRes
  1828.  
  1829. TSectionAdorner::~TSectionAdorner()
  1830.  
  1831. {
  1832.     fBorderRegion = DisposeIfRgnHandle(fBorderRegion);
  1833. } // TSectionAdorner::Free 
  1834.  
  1835. //----------------------------------------------------------------------------------------
  1836. // TSectionAdorner::InvalidateAdorner: 
  1837. //----------------------------------------------------------------------------------------
  1838. #pragma segment MAAdornerNonRes
  1839.  
  1840. void TSectionAdorner::InvalidateAdorner(TView* itsView)    // override 
  1841.  
  1842. {
  1843.     if (itsView && fBorderRegion)
  1844.         itsView->InvalidateRegion(fBorderRegion);
  1845. } // TSectionAdorner::InvalidateAdorner 
  1846.  
  1847. //----------------------------------------------------------------------------------------
  1848. // TSectionAdorner::DrawBorder: 
  1849. //----------------------------------------------------------------------------------------
  1850. #pragma segment MAAdornerRes
  1851.  
  1852. void TSectionAdorner::DrawBorder(const Pattern& whichPattern)
  1853.  
  1854. {
  1855.     PenNormal();
  1856.     PenMode(patXor);
  1857.     PenSize(3, 3);
  1858.     PenPat(&whichPattern);
  1859.  
  1860.     // Don't use FillRgn since it ignores the penMode. 
  1861.     FrameRgn(fBorderRegion);
  1862. } // TSectionAdorner::DrawBorder 
  1863.  
  1864.  
  1865. //========================================================================================
  1866. // CLASS TSubscriberAdorner
  1867. //========================================================================================
  1868. #undef Inherited
  1869. #define Inherited TSectionAdorner
  1870.  
  1871. #pragma segment MAAdornerNonRes
  1872. MA_DEFINE_CLASS_M1(TSubscriberAdorner, Inherited);
  1873.  
  1874. //----------------------------------------------------------------------------------------
  1875. // TSubscriberAdorner::TSubscriberAdorner: Empty constructor to satisfy the compiler.
  1876. //----------------------------------------------------------------------------------------
  1877. #pragma segment ConstructorRes
  1878.  
  1879. TSubscriberAdorner::TSubscriberAdorner()
  1880. {
  1881. } // TSubscriberAdorner::TSubscriberAdorner
  1882.  
  1883. //----------------------------------------------------------------------------------------
  1884. // TSubscriberAdorner destructor
  1885. //----------------------------------------------------------------------------------------
  1886. #pragma segment MADestructorRes
  1887.  
  1888. TSubscriberAdorner::~TSubscriberAdorner()
  1889. {
  1890. }
  1891.  
  1892. //----------------------------------------------------------------------------------------
  1893. // TSubscriberAdorner::ISubscriberAdorner: 
  1894. //----------------------------------------------------------------------------------------
  1895. #pragma segment MAAdornerNonRes
  1896.  
  1897. void TSubscriberAdorner::ISubscriberAdorner(IDType itsID,
  1898.                                               TSubscriber* itsSubscriber,
  1899.                                             RgnHandle itsBorderRegion)
  1900. {
  1901.     this->ISectionAdorner(itsID, itsSubscriber, itsBorderRegion);
  1902. } // TSubscriberAdorner::ISubscriberAdorner 
  1903.  
  1904. //----------------------------------------------------------------------------------------
  1905. // TSubscriberAdorner::DoHighlightSelection: 
  1906. //----------------------------------------------------------------------------------------
  1907. #pragma segment MAAdornerRes
  1908.  
  1909. void TSubscriberAdorner::DoHighlightSelection(TView* itsView,
  1910.                                               const VRect& ,
  1911.                                               HLState fromHL,
  1912.                                               HLState toHL)    // override 
  1913. {
  1914.     if (itsView)
  1915.     {
  1916.         TEditionDocument * itsDocument = (TEditionDocument *)itsView->fDocument;
  1917.         if ((itsDocument) && (itsDocument->IsBorderShown(fSection)))
  1918.             if ((fromHL == hlOn) && ((toHL == hlDim) || (toHL == hlOff)))
  1919.                 this->DrawBorder(qd.dkGray);            // turning off 
  1920.             else if (((fromHL == hlOff) || (fromHL == hlDim)) && (toHL == hlOn))
  1921.                 this->DrawBorder(qd.dkGray);            // turning on 
  1922.     }
  1923. } // TSubscriberAdorner::DoHighlightSelection 
  1924.  
  1925.  
  1926. //========================================================================================
  1927. // CLASS TPublisherAdorner
  1928. //========================================================================================
  1929. #undef Inherited
  1930. #define Inherited TSectionAdorner
  1931.  
  1932. #pragma segment MAAdornerNonRes
  1933. MA_DEFINE_CLASS_M1(TPublisherAdorner, Inherited);
  1934.  
  1935. //----------------------------------------------------------------------------------------
  1936. // TPublisherAdorner::TPublisherAdorner: Empty constructor to satisfy the compiler.
  1937. //----------------------------------------------------------------------------------------
  1938. #pragma segment ConstructorRes
  1939.  
  1940. TPublisherAdorner::TPublisherAdorner()
  1941. {
  1942. } // TPublisherAdorner::TPublisherAdorner
  1943.  
  1944. //----------------------------------------------------------------------------------------
  1945. // TPublisherAdorner destructor
  1946. //----------------------------------------------------------------------------------------
  1947. #pragma segment MADestructorRes
  1948.  
  1949. TPublisherAdorner::~TPublisherAdorner()
  1950. {
  1951. }
  1952.  
  1953. //----------------------------------------------------------------------------------------
  1954. // TPublisherAdorner::IPublisherAdorner: 
  1955. //----------------------------------------------------------------------------------------
  1956. #pragma segment MAAdornerNonRes
  1957.  
  1958. void TPublisherAdorner::IPublisherAdorner(IDType itsID,
  1959.                                           TPublisher* itsPublisher,
  1960.                                           RgnHandle itsBorderRegion)
  1961. {
  1962.     this->ISectionAdorner(itsID, itsPublisher, itsBorderRegion);
  1963. } // TPublisherAdorner::IPublisherAdorner 
  1964.  
  1965. //----------------------------------------------------------------------------------------
  1966. // TPublisherAdorner::DoHighlightSelection: 
  1967. //----------------------------------------------------------------------------------------
  1968. #pragma segment MAAdornerRes
  1969.  
  1970. void TPublisherAdorner::DoHighlightSelection(TView* itsView,
  1971.                                              const VRect& ,
  1972.                                              HLState fromHL,
  1973.                                              HLState toHL)    // override 
  1974. {
  1975.     if (itsView)
  1976.     {
  1977.         TEditionDocument * itsDocument = (TEditionDocument *)itsView->fDocument;
  1978.         if ((itsDocument) && (itsDocument->IsBorderShown(fSection)))
  1979.             if ((fromHL == hlOn) && ((toHL == hlDim) || (toHL == hlOff)))
  1980.                 this->DrawBorder(qd.gray);            // turning off 
  1981.             else if (((fromHL == hlOff) || (fromHL == hlDim)) && (toHL == hlOn))
  1982.                 this->DrawBorder(qd.gray);            // turning on 
  1983.     }
  1984. } // TPublisherAdorner::DoHighlightSelection 
  1985.  
  1986.  
  1987. //========================================================================================
  1988. // CLASS TSectionBehavior
  1989. //========================================================================================
  1990. #undef Inherited
  1991. #define Inherited TBehavior
  1992.  
  1993. #pragma segment MAOpen
  1994. MA_DEFINE_CLASS_M1(TSectionBehavior, Inherited);
  1995.  
  1996. //----------------------------------------------------------------------------------------
  1997. // TSectionBehavior::TSectionBehavior: Empty constructor to satisfy the compiler.
  1998. //----------------------------------------------------------------------------------------
  1999. #pragma segment ConstructorRes
  2000.  
  2001. TSectionBehavior::TSectionBehavior()
  2002. {
  2003. } // TSectionBehavior::TSectionBehavior
  2004.  
  2005. //----------------------------------------------------------------------------------------
  2006. // TSectionBehavior destructor
  2007. //----------------------------------------------------------------------------------------
  2008. #pragma segment MADestructorRes
  2009.  
  2010. TSectionBehavior::~TSectionBehavior()
  2011. {
  2012. }
  2013.  
  2014. //----------------------------------------------------------------------------------------
  2015. // TSectionBehavior::ISectionBehavior: 
  2016. //----------------------------------------------------------------------------------------
  2017. #pragma segment MAOpen
  2018.  
  2019. void TSectionBehavior::ISectionBehavior(IDType itsIdentifier)
  2020. {
  2021.     this->IBehavior(itsIdentifier);
  2022. } // TSectionBehavior::ISectionBehavior 
  2023.  
  2024. //----------------------------------------------------------------------------------------
  2025. // TSectionBehavior::DoMouseCommand: 
  2026. //----------------------------------------------------------------------------------------
  2027. #pragma segment MASelCommand
  2028.  
  2029. Boolean TSectionBehavior::DoMouseCommand(VPoint& theMouse,
  2030.                                          TToolboxEvent* event,
  2031.                                          CPoint hysteresis)
  2032. {
  2033.     TView* itsView = (TView*) fOwner;
  2034.     // itsView->Focus();
  2035.     CPoint qdMouse = itsView->ViewToQDPt(theMouse);
  2036.  
  2037.     CAdornerIterator iter(itsView);
  2038.     
  2039.     for (TAdorner* theAdorner = iter.FirstAdorner(); iter.More(); theAdorner = iter.NextAdorner())
  2040.     {
  2041.         if ((theAdorner->fIdentifier == kPublisherAdornerID)
  2042.             || (theAdorner->fIdentifier == kSubscriberAdornerID))
  2043.         {
  2044.             TEditionDocument* itsEditionDocument = (TEditionDocument*) itsView->fDocument;
  2045.             TSectionAdorner* itsSectionAdorner = (TSectionAdorner*)theAdorner;
  2046.             TSection* itsSection = itsSectionAdorner->fSection;
  2047.             if ((event->fClickCount == 1) && (PtInRgn(qdMouse, itsSectionAdorner->fBorderRegion)))
  2048.             {
  2049.                 TDesignator* theSelection = itsSection->fDesignator;
  2050.                 if (theSelection)
  2051.                 {
  2052.                     if ((theSelection = (TDesignator*) theSelection->Clone()) != NULL)
  2053.                         ((TView*) fOwner)->SetUserSelection(theSelection);
  2054.                 }
  2055.                 return TRUE;
  2056.             }
  2057.             else if ((event->fClickCount > 1) && (PtInRgn(qdMouse, itsSectionAdorner->fBorderRegion)))
  2058.             {
  2059.                 if (itsSection->GetSectionType() == stPublisher)
  2060.                     itsEditionDocument->DoPublisherOptions((TPublisher *) itsSection);
  2061.                 else
  2062.                 {
  2063.                     if (event->IsOptionKeyPressed())
  2064.                         ((TSubscriber*)itsSection)->OpenPublisher();
  2065.                     else
  2066.                         itsEditionDocument->DoSubscriberOptions((TSubscriber*)itsSection);
  2067.                 }
  2068.                 return TRUE;
  2069.             }
  2070.         }
  2071.     }
  2072.     
  2073.     return Inherited::DoMouseCommand(theMouse, event, hysteresis);
  2074. } // TSectionBehavior::DoMouseCommand 
  2075.  
  2076. //----------------------------------------------------------------------------------------
  2077. // TSectionBehavior::GetStandardSignature: 
  2078. //----------------------------------------------------------------------------------------
  2079. #pragma segment MAWriteResource
  2080.  
  2081. IDType TSectionBehavior::GetStandardSignature()
  2082. {
  2083.     return kSectionBehavior;
  2084. } // TSectionBehavior::GetStandardSignature 
  2085.  
  2086. //----------------------------------------------------------------------------------------
  2087. // End of UEditionDocument.cp
  2088.  
  2089. #pragma segment Inline
  2090.